$(function(){
   var
       oUseNameIp = $('#useName'),
       oUseP1 = $('.use .p1'),
       oPassWardIp = $('#passWard'),
       oUseP2 = $('.use .p2');

    //获得cookie useName cookie
    oUseNameIp.val(getCookie("useName"));
    oPassWardIp.val(getCookie('passWard'));

  /*  判断用户名输入*/
    oUseNameIp.focus(function(){
        oUseP1.css({display:'none'});
        oUseNameIp.val(function(){
            return this.value;
        });
        if (oUseNameIp.val()=='已验证手机号/邮箱'){
            oUseNameIp.val('');
        }
    });
    oUseNameIp.blur(function(){
        if(oUseNameIp.val()==''||oUseNameIp.val()=='已验证手机号/邮箱'){
            oUseP1.css({display:'block'});
            oUseP1.html('请输入正确的手机号或邮箱')
            return
        }
        var reg1=/(^1[34578]\d{9}$)|(^\w+@\w\.[a-zA-Z]{2,3}$)/;
        if(reg1.test(oUseNameIp.val())==false){
            oUseP1.css({display:'block'});
            oUseP1.html('请输入正确的手机号或邮箱')
            return;
        }
        if(getCookie('useName1')!=oUseNameIp.val()){
            oUseP1.css({display:'block'});
            oUseP1.html('用户名有误  !!!')
        }
    });


    /*判断密码*/
    oPassWardIp.focus(function(){
        oUseP2.css({display:'none'});
    });

    oPassWardIp.blur(function(){
        if(getCookie('passWard1')!=oPassWardIp.val()){
            oUseP2.css({display:'block'});
        }
    });



    //验证码
    var
        oYanZanIp = $('.yanZh>input'),
        oYanZanTS = $('.yanZh .tiShi a'),
        oYanZanTSImg = $('.tiShi img'),
        arr =[0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','F','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
        /*arr=['../img验证/getRandom%20(1).jpg','../img验证/getRandom%20(2).jpg','../img验证/getRandom%20(3).jpg','../img验证/getRandom%20(4).jpg','../img验证/getRandom%20(5).jpg','../img验证/getRandom%20(6).jpg','../img验证/getRandom%20(7).jpg','../img验证/getRandom%20(8).jpg','../img验证/getRandom%20(9).jpg','../img验证/getRandom%20(10).jpg','../img验证/getRandom%20(11).jpg','../img验证/getRandom%20(12).jpg'];*/
       arr1=[];
    oYanZanTS.ready(function(){
        //var aIndex = parseInt(Math.random()*12);
        //oYanZanTSImg.attr('src',arr[aIndex])
        arr1=[];
        for(var i=0;i<4;i++){
            var aIndex = parseInt(Math.random()*52);
            arr1.push(arr[aIndex]);
        }
        oYanZanTS.html(arr1);
    });
    oYanZanTS.click(function(){
        //var aIndex = parseInt(Math.random()*12);
        //oYanZanTSImg.attr('src',arr[aIndex])
        arr1=[];
        for(var i=0;i<4;i++){
            var aIndex = parseInt(Math.random()*52);
            arr1.push(arr[aIndex]);
        }
        oYanZanTS.html(arr1);
    });

    //提交按钮的判断
    var
        oBtn = $('.btn>input'),
        oBtnP = $('.btn-p');
    oBtn.click(function(){

        console.log(oYanZanIp.val().toLocaleLowerCase())
        if(oYanZanIp.val().toLocaleLowerCase() != arr1.join('').toLocaleLowerCase()){
            oBtnP.css({display:'block'});
        }
        if(getCookie('passWard1')==oPassWardIp.val() && getCookie('useName1')==oUseNameIp.val()&&oYanZanIp.val().toLocaleLowerCase() == arr1.join('').toLocaleLowerCase()){
            console.log(getCookie('passWard1')==oPassWardIp.val() && getCookie('useName1')==oUseNameIp.val())
            $(window)[0].location.assign('http://localhost:63342/%E9%AD%85%E5%8A%9B%E6%83%A0%E9%A1%B9%E7%9B%AE/html/MEl-Home.html');
        }

        //当按钮按下时 设置cookie
        setCookie('useName', oUseNameIp.val(), 7, '/');
        setCookie('passWard', oPassWardIp.val(), 7, '/');
    });
    //radio
    var
        oEm      = $('.f-bottom em'),
        oFlag    = true,
        oCommenRegisterA1 = $('.commen-register .a1'),
        oCommenRegisterA2 = $('.commen-register .a2');
    oEm.click(function(){
        if(oFlag){
            oEm.css({backgroundImage:"url('../images/icon_not_selected.png')"});
            oFlag=false;
        }else {
            oEm.css({backgroundImage: "url('../images/icon_selected.png')"});
            oFlag=true;
        }
    });

    oCommenRegisterA1.mouseenter(function() {
        oCommenRegisterA1.css({backgroundImage: "url('../images/icon_weibo_03.png')"})
    }).mouseleave(function(){
        oCommenRegisterA1.css({backgroundImage: "url('../images/icon_weibo.png')"})
    });
    oCommenRegisterA2.mouseenter(function() {
        oCommenRegisterA2.css({backgroundImage: "url('../images/icon_zhifubao_03.png')"})
    }).mouseleave(function(){
        oCommenRegisterA2.css({backgroundImage: "url('../images/icon_zhifubao.png')"})
    })

    });
